VisionPro 您所在的位置:网站首页 CreateContentBitMap 出错 VisionPro

VisionPro

2023-04-06 01:54| 来源: 网络整理| 查看: 265

private void Form1_Load(object sender, EventArgs e)        {            cogDisplayStatusBarV21.Display = cogRecordDisplay1;            cogToolBlock1 = (CogToolBlock)CogSerializer.LoadObjectFromFile(@"C:\Users\20857\Desktop\TouchBar现场\测试程序\PixelMapToolBlock.vpp");            cogToolBlock1.Run();            cogRecordDisplay1.Record = cogToolBlock1.CreateLastRunRecord();            cogRecordDisplay1.Image = ((CogPixelMapTool)cogToolBlock1.Tools["CogPixelMapTool1"]).OutputImage;                        Bitmap bitmap= (Bitmap)cogRecordDisplay1.CreateContentBitmap(CogDisplayContentBitmapConstants.Image, null, 0);            Point point = new Point(500, 880);            cutImage(bitmap, point, 1500, 400).Save(@"C:\Users\20857\Desktop\TouchBar现场\测试程序\1.bmp");        }        ///         /// 截取图片区域,返回所截取的图片        ///         ///         ///         ///         ///         ///         private Image cutImage(Image SrcImage, Point pos, int cutWidth, int cutHeight)        {            Image cutedImage = null;            //先初始化一个位图对象,来存储截取后的图像            Bitmap bmpDest = new Bitmap(cutWidth, cutHeight);            Graphics g = Graphics.FromImage(bmpDest);            //矩形定义,将要在被截取的图像上要截取的图像区域的左顶点位置和截取的大小            Rectangle rectSource = new Rectangle(pos.X, pos.Y, cutWidth, cutHeight);            //矩形定义,将要把 截取的图像区域 绘制到初始化的位图的位置和大小            //rectDest说明,将把截取的区域,从位图左顶点开始绘制,绘制截取的区域原来大小            Rectangle rectDest = new Rectangle(0, 0, cutWidth, cutHeight);            //第一个参数就是加载你要截取的图像对象,第二个和第三个参数及如上所说定义截取和绘制图像过程中的相关属性,第四个属性定义了属性值所使用的度量单位            g.DrawImage(SrcImage, rectDest, rectSource, GraphicsUnit.Pixel);            //在GUI上显示被截取的图像            cutedImage = (Image)bmpDest;            g.Dispose();            return cutedImage;        }

来源:https://www.cnblogs.com/forblueskies/p/11441227.html



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有